// packageTab/pages/double11/double11.js
import {
	promotion_img,
  convert,
  getTbTKL
} from '../../../utils/imapi.js';
import shareFun from '../../../utils/shareFun.js';
const app =  getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tg_bg_img:'', //推广背景图链接
        shareImg:'',// 分享背景图链接
        shareText:'',// 分享文字
        gbText:'',// 自购文字
        appIcon:'', //跳转app图片
        title:'',
        show_load: false,
        shareColor:'', //分享按键颜色
        gbColor:'', // 自购颜色
        extras:'' , //
        extras_obj:null,
        appName:'',
        share_processor:'',
        buy_processor:'',
        is_show_big:0,
        content:'',
        support_fans:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

       
        shareFun.hidenShareMenu()

        let item= JSON.parse(decodeURIComponent(options.json_data))
        let extras_obj= JSON.parse(item.extras);
        console.log(extras_obj);
        console.log(item);
        this.setData({
            tg_bg_img:item.tg_bg_img,
            shareImg:item.tg_share_img,
            shareText:item.btn_share_text,
            gbText:item.btn_gobuy_text,
            extras:item.extras,
            appIcon:item.to_app_logo,
            title:item.title,
            shareColor:item.but_share_cls,
            gbColor:item.btn_gobuy_cls,
            extras_obj:extras_obj,
            appName:item.to_app_name,
            share_processor:item.share_processor,
            buy_processor:item.buy_processor,
            support_fans:item.support_fans
        })
       
        // console.log('----:',options.json_data)
       
        // console.log(item);
        // let uid=app.globalData.userInfo.uid;

        // console.log('----options.extras:',items.extras)
        // let extras_obj= JSON.parse(items.extras);

        // extras_obj.uid = uid
        // console.log('----extras_obj:',extras_obj)

    },

    async go_buy_func() {
        //设置登陆权限
        if (!app.is_auth()) {
            wx.navigateTo({
                url: '/pages/login/login',
            })
            return;
        }
        this.setData({
            show_load: true
        })
        console.log(this.data.extras_obj);
        const uid =app.globalData.userInfo.uid
        const extras_Obj = this.data.extras_obj
        
        extras_Obj.uid = uid
        extras_Obj.buyer_uid = uid
        // extras_Obj.tip_text=this.data.appName
        console.log(extras_Obj);
        var con = await convert(
          extras_Obj
        );

        console.log(con);


        var that = this;
        wx.navigateToMiniProgram({
            appId: con.data.app_id,
            path: con.data.wxapp_page_path,
            
            success() {
                that.setData({
                    show_load: false
                })
            },
            fail(res) {
                that.setData({
                    show_load: false
                })
            }
        })

    },
    closeDown1() {
        this.setData({
            show_load: false
        })
    },
    // share() {
    // 	var image=[];
    // 	image.push(this.data.img1);
    // 	wx.previewImage({
    // 		current: this.data.img1, 
    // 		urls: image
    // 	})
    // },
    async  share_func(){ // 显示推广海报弹出
        //var index = e.currentTarget.dataset.index
       // console.log(index)
        /*this.setData({
          cur_show_img_index:index,
          is_show_big:1
            })*/
    
        if(!app.is_auth()){
          
          wx.showToast({
            title: '请先登陆，才能生成推广码哦',
          })
    
          wx.navigateTo({
            url: '/pages/login/login',
          })
    
          return
    
        }
    
       wx.showLoading({
         title: '海报生成中...',
       })
    
        const link_data = await promotion_img({
          bg:this.data.shareImg,
          opt:2,
          uid:app.globalData.userInfo.uid,
          scene: '10006,'+app.globalData.userInfo.uid //场景，用户uid
        })
        wx.hideLoading()
    
        var le=[];
          le.push(link_data.data);
        wx.previewImage({
            current:link_data.data,
            urls:le
        })
    
      },

    async  go_buy_tkl_func(){ //淘宝 淘口令方式
        // 先登录
        if(!app.is_auth()){
          wx.showToast({
            title: '请先登陆，才能生成推广码哦',
          })   
          wx.navigateTo({
            url: '/pages/login/login',
          })
          return
        }
        const uid =app.globalData.userInfo.uid
        const extras_Obj = this.data.extras_obj
        
        extras_Obj.uid = uid
        extras_Obj.buyer_uid = uid
        // extras_Obj.tip_text=this.data.appName
        console.log(extras_Obj);
        wx.showLoading({
          title: '加载中',
        })
        var con = await convert(
          {
            p:'ELM',
            content:'20150318020001156'
          }
        );

        console.log(con);
        this.setData({
          zhuan_url: con.data.coupon_tpwd,
          is_show_big: 1,
        })
        wx.hideLoading({})
      },
      closeDown() {
        console.log(111111111111111111);
        this.setData({
          is_show_big: 0
        })
      },
      copy(e) {
        var that = this;
        var cont = e.currentTarget.dataset.cont;
        wx.setClipboardData({
          data: cont,
          success() {
            wx.showToast({
              title: '复制成功'
            })
            setTimeout(() => {
              that.setData({
                // is_show_big1: 0,
                is_show_big: 0
              })
            }, 1000);
          },
        })
      },
      quanfenShare() {
        
      },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {

   }
})